package la.iok.hzsvn.lewin.movie.cloud.service;

import la.iok.hzsvn.lewin.movie.cloud.entity.LoginRecord;
import la.iok.hzsvn.lewin.movie.cloud.entity.User;
import la.iok.hzsvn.lewin.movie.cloud.mapper.LoginRecordMapper;
import la.iok.hzsvn.lewin.movie.cloud.model.UserDeviceParam;
import la.iok.hzsvn.lewin.mybatis.service.BaseServiceImpl;
import la.iok.hzsvn.share.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

@Service
public class LoginRecordServiceImpl extends BaseServiceImpl<LoginRecord, LoginRecordMapper,Long> implements LoginRecordService {
    public LoginRecordServiceImpl(LoginRecordMapper mapper) {
        super(mapper);
    }

    @Nullable
    @Override
    public Long save(@Nullable User user, @Nullable UserDeviceParam param,int loginType) {
        if(user == null){
            return null;
        }
        LoginRecord record = new LoginRecord();
        if(param != null){
            BeanUtils.copyProperties(param,record);
        }
        record.setPhoneNumber(user.getPhoneNumber());
        record.setUserId(user.getId());
        record.setLoginType(loginType);
        insertSelective(record);
        return record.getId();
    }
}
